#!/bin/sh /etc/rc.common
# Copyright (C) 2015 OpenWrt.org

START=99

USE_PROCD=1

set_lan_domain(){
	hosts_path="/etc/hosts"
	lan_ip=$(ip addr show br-lan | grep -w inet | awk '{print $2}' | cut -d/ -f 1)
	sed -i '/gpt.hiswi.cn/d' "${hosts_path}"
	echo "${lan_ip} gpt.hiswi.cn" >> "${hosts_path}"
}

create_ipsets(){

	[ -f /tmp/wifi_first_configing ] && {
		sleep 60
	}

	# private net
	# ipset restore -f /etc/ipsets/private_net 2>/dev/null

	# china net
	#ipset restore -f /etc/ipsets/china_net 2>/dev/null

	#dns net
	#ipset restore -f /etc/ipsets/dns_net 2>/dev/null
}

start_service() {
	#设置opkg 软件源
	sed -i '/^src\/gz/d; /^# src\/gz/d' /etc/opkg.conf
	echo "src/gz hiswi_ar71 http://fw.hiswi.cn/ar71xx/packages" >> /etc/opkg.conf
	echo "src/gz hiswi_mt7621 http://fw.hiswi.cn/ramips/packages/base" >> /etc/opkg.conf
	set_lan_domain
	/usr/sbin/rsstats &
	rm -rf /tmp/dnsmasq.d/ ;cp -rf /etc/dnsmasq.d/ /tmp/

	create_ipsets &
}

stop_service(){
	killall rsstats
}
